<template>
	<uv-modal ref="orderCcModal" title="取消订单" :cancelColor="theme == 'fs'?'#006BFE': '#0BCA89'"
		:confirmColor="theme == 'fs'?'#006BFE': '#0BCA89'" :showCancelButton="true" cancelText="取消" confirmText="确认"
		:asyncClose="true" @confirm="handleConfirmOder" @cancel="onCancel">
		<view class="w-100">
			<view class="text-black text-bold margin-bottom-sm">
				取消原因
			</view>
			<uv-textarea v-model="reason" placeholder="请填写取消原因"></uv-textarea>
		</view>
	</uv-modal>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				reason: '',
				theme: ''
			}
		},
		methods: {
			show(data) {
				this.id = data.id
				this.theme = data.theme
				this.$refs.orderCcModal.open();
			},
			onCancel() {
				this.$refs.orderCcModal.closeLoading()
				this.$refs.orderCcModal.close();
				// this.$http.post(`/cadre/assignOrder/cancelOrder`,{}, {
				// 	params: {
				// 		orderId: this.id,
				// 		timeout: 2
				// 	}
				// }).then(res => {
				// 	uni.showToast({
				// 		title:res.msg
				// 	})
				// 	this.$emit('success')
				// 	this.$refs.orderCcModal.closeLoading()
				// 	this.$refs.orderCcModal.close();
				// })
			},
			handleConfirmOder() {
				if(!this.reason) {
					this.$refs.orderCcModal.closeLoading()
					uni.showToast({
						icon: 'none',
						title: '请填写原因！'
					})
				}
				this.$http.get(this.theme == 'fs' ? `/cadre/assignOrder/cancelOrder` : '/cadre/highSeasOrder/cancel', {
					params: {
						orderId: this.id,
						reason: this.reason,
						timeout: 2
					}
				}).then(res => {
					if (res.code === 200) {
					this.$emit('success')
					this.$refs.orderCcModal.closeLoading()
					this.$refs.orderCcModal.close();
					} else if (res.code === 500) {
						this.$refs.orderCcModal.closeLoading()
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					} else {
						this.$refs.orderCcModal.closeLoading()
						uni.showToast({
							title: res.msg || '操作失败',
							icon: 'none'
						});
					}
				})
			}
		},
	}
</script>

<style>
</style>